// ==UserScript==
// @name         Storage Cleaner
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  清除页面所有存储数据
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建Apple风格按钮
    const button = document.createElement('button');
    button.innerHTML = '清除存储';
    Object.assign(button.style, {
        'position': 'fixed',
        'top': '20px',
        'right': '20px',
        'z-index': '9999',
        'padding': '8px 16px',
        'border-radius': '20px',
        'border': 'none',
        'background-color': '#007AFF',
        'color': 'white',
        'font-family': '-apple-system, BlinkMacSystemFont, sans-serif',
        'font-size': '14px',
        'font-weight': '500',
        'cursor': 'pointer',
        'box-shadow': '0 2px 8px rgba(0, 0, 0, 0.1)',
        'transition': 'all 0.2s ease'
    });

    // 添加悬停效果
    button.addEventListener('mouseenter', () => {
        button.style.transform = 'scale(1.05)';
        button.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.15)';
    });
    button.addEventListener('mouseleave', () => {
        button.style.transform = 'scale(1)';
        button.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.1)';
    });

    // 点击事件处理
    button.addEventListener('click', () => {
        try {
            // 清除localStorage
            localStorage.clear();
            // 清除sessionStorage
            sessionStorage.clear();
            // 清除cookie
            document.cookie.split(';').forEach(cookie => {
                const eqPos = cookie.indexOf('=');
                const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
                document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
            });
            
            // Apple风格提示
            const notification = document.createElement('div');
            notification.textContent = '存储数据已清除 ✓';
            Object.assign(notification.style, {
                'position': 'fixed',
                'top': '60px',
                'right': '20px',
                'z-index': '9999',
                'padding': '8px 16px',
                'border-radius': '8px',
                'background-color': '#34C759',
                'color': 'white',
                'font-family': '-apple-system, BlinkMacSystemFont, sans-serif',
                'font-size': '14px',
                'font-weight': '500',
                'box-shadow': '0 2px 8px rgba(0, 0, 0, 0.1)',
                'animation': 'fadeInOut 2.5s ease forwards'
            });
            
            document.body.appendChild(notification);
            setTimeout(() => {
                notification.remove();
            }, 2500);
            
        } catch (e) {
            console.error('清除存储时出错:', e);
        }
    });

    // 添加CSS动画
    const style = document.createElement('style');
    style.textContent = `
        @keyframes fadeInOut {
            0% { opacity: 0; transform: translateY(-10px); }
            10% { opacity: 1; transform: translateY(0); }
            90% { opacity: 1; transform: translateY(0); }
            100% { opacity: 0; transform: translateY(-10px); }
        }
    `;
    document.head.appendChild(style);
    
    // 添加按钮到页面
    document.body.appendChild(button);
})();